#!/usr/bin/php
<?php
/*
 * Copyright (C) 2013-2014 RuneAudio Team
 * http://www.runeaudio.com
 *
 * RuneUI
 * copyright (C) 2013-2014 - Andrea Coiutti (aka ACX) & Simone De Gregori (aka Orion)
 *
 * RuneOS
 * copyright (C) 2013-2014 - Simone De Gregori (aka Orion) & Carmelo San Giovanni (aka Um3ggh1U)
 *
 * RuneAudio website and logo
 * copyright (C) 2013-2014 - ACX webdesign (Andrea Coiutti)
 *
 * This Program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3, or (at your option)
 * any later version.
 *
 * This Program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with RuneAudio; see the file COPYING.  If not, see
 * <http://www.gnu.org/licenses/gpl-3.0.txt>.
 *
 *  file: command/refresh_ao
 *  version: 1.3
 *  coder: Simone De Gregori
 *
 */
// common include
ini_set('display_errors', '1');
ini_set('error_reporting', -1);
ini_set('error_log', '/var/log/runeaudio/refresh_ao.log');
// Connect to Redis backend
$redis = new Redis();
$redis->connect('/tmp/redis.sock');
include('/var/www/app/libs/runeaudio.php');
$lock = $redis->get('lock_refresh_ao');
runelog('lock status ', $lock);
// startup
runelog('--------------------------- start Audio Outputs refresh ---------------------------');
// refesh audio hardware status (soundcards and MPD config)
if ($lock === '0') {
    $redis->set('lock_refresh_ao', '1');
    wrk_mpdconf($redis, 'refresh');
    ui_notify('Audio Output', 'configuration changed.');    
    sleep(1);
    $redis->set('lock_refresh_ao', '0');
} else {
    echo "LOCKED!";
}
// startup
runelog('-------------------------- #finish Audio Outputs refresh# --------------------------');
runelog('lock status ', $redis->get('lock_refresh_ao'));
// close Redis connection
$redis->close();
